<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-productVersion-edit" th:object="${productVersion}">
            <input id="id" name="id" th:field="*{id}"  type="hidden">
			<div class="form-group">
				<label class="col-sm-3 control-label">所属产品：</label>
				<div class="col-sm-8">
					<select id="product" name="product" class="form-control m-b">
						<!--<option th:each="product:${products}" th:value="${product.id}" th:text="${product.name}" th:disabled="${product.status == '1'}"></option>-->
						<option th:each="product:${products}" th:value="${product.id}" th:text="${product.name}" th:disabled="${product.status == '1'}" th:selected="${productVersion.productId==product.id}"></option>
					</select>
				</div>
			</div>
			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">产品ID：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="productId" name="productId" th:field="*{productId}" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">产品名称：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="productName" name="productName" th:field="*{productName}" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
			<div class="form-group">	
				<label class="col-sm-3 control-label">版本号：</label>
				<div class="col-sm-8">
					<input id="version" name="version" th:field="*{version}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">版本名称：</label>
				<div class="col-sm-8">
					<input id="name" name="name" th:field="*{name}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">是否发布：</label>
				<div class="col-sm-8">
					<div class="onoffswitch">
						<input type="checkbox" th:checked="${productVersion.isPublished == '1' ? true : false}" class="onoffswitch-checkbox" id="isPublished" name="isPublished">
						<label class="onoffswitch-label" for="isPublished">
							<span class="onoffswitch-inner"></span>
							<span class="onoffswitch-switch"></span>
						</label>
					</div>
				</div>
			</div>
			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">是否发布：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="isPublished" name="isPublished" th:field="*{isPublished}" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "system/productVersion"
		$("#form-productVersion-edit").validate({
			rules:{
                version:{
                    required:true,
                    minlength: 2,
                    maxlength: 20,
                },
                product:{
                    required:true
                },
                isPublished:{
                    required:true
                }
			}
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
                // $.operate.save(prefix + "/edit", $('#form-productVersion-edit').serialize());
				edit();
            }
	    }

        function edit() {
            var id = $("input[name='id']").val();
            var productId = $("#product").val();
            var productName = $("#product option:selected").text();
            var version = $("input[name='version']").val();
            var versionName = $("input[name='name']").val();
            var isPublished = $("input[name='isPublished']").is(':checked') == true ? 1 : 0;
            $.ajax({
                cache : true,
                type : "POST",
                url : prefix + "/edit",
                data :{
					"id": id,
                    "productId": productId,
                    "productName": productName,
                    "version": version,
                    "name": versionName,
                    "isPublished": isPublished
                },
                async : false,
                error : function(request) {
                    $.modal.alertError("系统错误");
                },
                success : function(data) {
                    $.operate.successCallback(data);
                }
            });
        }
	</script>
</body>
</html>
